import request from '@/utils/request';
import type { BaseTreeModel, TreeNodeModel, ResponseBaseData } from '@/api/model/baseModel';

export const basePath = '/demo/template/demotreegrids';
/** 树形表格示例 */
export interface DemoTreegridDto extends BaseTreeModel {
  /** 父节点id */
  parentId?: string;
  /** 用户 */
  demoUserId?: string;
  demoUserIdAlias?: string;
  /** 标题 */
  demoTitle?: string;
  /** 部门 */
  demoDeptId?: string;
  demoDeptIdAlias?: string;
  /** 角色 */
  demoRoleId?: string;
  demoRoleIdAlias?: string;
  /** 群组 */
  demoGroupId?: string;
  demoGroupIdAlias?: string;
  /** 岗位 */
  demoPositionId?: string;
  demoPositionIdAlias?: string;
  /** 单选 */
  demoRadio?: string;
  demoRadioName?: string;
  /** 单选（按钮） */
  demoRadioButton?: string;
  demoRadioButtonName?: string;
  /** 复选 */
  demoCheckbox?: any;
  /** 下拉 */
  demoSelect?: any;
  /** 下拉多选 */
  demoSelectMultiple?: any;
  /** 密级 */
  secretLevel?: any;
  /** 开关 */
  demoSwitch?: any;
  /** 小数 */
  demoNumber?: number;
  /** 整数 */
  demoInteger?: number;
  /** 日期 */
  demoDate?: any;
  demoDateBegin?: any;
  demoDateEnd?: any;
  /** 日期时间 */
  demoDateTime?: any;
  demoDateTimeBegin?: any;
  demoDateTimeEnd?: any;
  /** 必填 */
  demoNotnull?: string;
  /** 编码 */
  demoCode?: any;
  /** 电话(正则) */
  demoPhone?: string;
  /** 邮箱(正则) */
  demoEmail?: string;
  /** 网址(正则) */
  demoWebsite?: string;
  /** 唯一值 */
  demoUnique?: string;
  /** 弹窗 */
  demoModalSelect?: string;
  demoModalSelectAlias?: string;
  /** 富文本 */
  demoRichtext?: string;
  /** 多行文本 */
  demoTextarea?: string;
  /** 树全路径 */
  treePath?: string;
  /** 排序号(本级） */
  treeSort?: number;
  /** 排序号(所有级） */
  treeSorts?: string;
  /** 是否叶子节点 */
  treeLeaf?: string;
  /** 节点层级 */
  treeLevel?: number;
}
// 根据parentId获取子节点
export function getDemoTreegridNode(level: number, parentId: string): Promise<ResponseBaseData<TreeNodeModel[]>> {
  return request.get(`${basePath}/get-treegrid/${level}/${parentId}/v1`);
}

// 树列表查询
export function searchDemoTreegrid(params: any): Promise<ResponseBaseData<TreeNodeModel>> {
  return request.post(`${basePath}/find-node-list/v1`, params);
}

// 展开树
export function expandDemoTreegrid(treeId: string): Promise<ResponseBaseData<TreeNodeModel[]>> {
  return request.get(`${basePath}/expandTree/${treeId}/v1`);
}

// 保存表单数据
export function saveDemoTreegrid(form: DemoTreegridDto): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/save/v1`, form);
}

// 根据id集合删除数据
export function delDemoTreegrid(ids: string): Promise<ResponseBaseData<any>> {
  return request.delete(`${basePath}/delete-by-id/${ids}/v1`, {});
}

// 获取表单数据
export function getDemoTreegrid(id: string): Promise<ResponseBaseData<DemoTreegridDto>> {
  return request.get(`${basePath}/get/${id}/v1`);
}

/** 更新开关 */
export function updateDemoSwitch(id: string, demoSwitch: string): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/update-demo-switch/v1/${id}/${demoSwitch}`);
}

/** 校验唯一值唯一性 */
export function checkDemoUniqueUnique(param: any): Promise<ResponseBaseData<any>> {
  return request.post(`${basePath}/check-demo-unique-unique/v1`, param);
}
